<?php

/**
 * Tabela do texto inicial.
 *
 * @author Fernando Dias Oliveira <rodox17@gmail.com>
 * @package lore
 * @subpackage model
 */

class caf01 extends Zend_Db_Table_Abstract  
{
	protected $_table   = "caf01";
	protected $_primary = "caf01_cod";
	
	public function getUserByPass($pass)
	{
		$obj = $this->fetchAll("caf01_password = '$pass'")->current();
		$arr = array();
		
		if(is_object($obj))
		{
			$arr = $obj->toArray();
			
			if(is_array($arr))
			{
				return $arr;
			}
		}
		
		return 0;
	}
	
	public function save($data)
	{
		$this->insert($data);
	}
	
	public function getUltimoId()
	{
		$id = rand(000, 999);
		
		switch (strlen($id))
		{
			case 1: $id = "00$id";break;
			case 2: $id = "0$id";break;
		}
		
		if(!$this->fetchRow("caf01_password = $id"))
			return $id;
		else
			return rand(000, 999);
	}
	
	public function getAll()
	{
		return $this->fetchAll("caf01_status = 1")->toArray();
	}
	
	public function getDropDrow()
	{
		$arr   = array();
		
		$arr[""] = "Todos";
		
		foreach ($this->fetchAll() as $val)
		{
			$arr[$val["caf01_cod"]] = $val["caf01_user"];
		}
		
		return $arr;
	}
}

?>
